/*
 * ListenerList.java
 *
 * Created on 2007/12/28 +0900
 *
 * $Revision: 60 $
 * $Date: 2008-12-28 19:27:48 +0000 (Sun, 28 Dec 2008) $
 */

package org.gikolet.framework.util;

import java.util.Vector;

/**
 * @author Tetsutaro (latest modification by $Author: tetsutaro.ss $)
 * @version $Revision: 60 $ $Date: 2008-12-28 19:27:48 +0000 (Sun, 28 Dec 2008) $
 */
public class ListenerList {
    private static final Listener[] EMPTY_LISTENER_ARRAY = new Listener[0];

    private Vector listeners;

    public void add(Listener listener) {
	Assert.isNotNull(listener);

	if (this.listeners == null) {
	    this.listeners = new Vector();
	}
	this.listeners.addElement(listener);
    }

    public void clear() {
	if (this.listeners != null) {
	    this.listeners.removeAllElements();
	}
    }

    public Listener[] getListeners() {
	if (this.listeners == null || this.listeners.isEmpty()) {
	    return ListenerList.EMPTY_LISTENER_ARRAY;
	}
	Listener[] objs = new Listener[this.listeners.size()];
	this.listeners.copyInto(objs);

	return objs;
    }

    public boolean isEmpty() {
	return (this.listeners == null) ? true : this.listeners.isEmpty();
    }

    public void remove(Listener listener) {
	Assert.isNotNull(listener);

	if (this.listeners != null) {
	    this.listeners.removeElement(listener);
	}
    }

    public int getSize() {
	return (this.listeners == null) ? 0 : this.listeners.size();
    }
}
